package com.ruoyi.web.controller.enterprise;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.enterprise.domain.ProductionProcess;
import com.ruoyi.enterprise.service.IProductionProcessService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 生产工艺Controller
 * 
 * @author ruoyi
 * @date 2021-08-10
 */
@RestController
@RequestMapping("/enterprise/process")
public class ProductionProcessController extends BaseController
{
    @Autowired
    private IProductionProcessService productionProcessService;

    /**
     * 查询生产工艺列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:process:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductionProcess productionProcess)
    {
        startPage();
        List<ProductionProcess> list = productionProcessService.selectProductionProcessList(productionProcess);
        return getDataTable(list);
    }

    /**
     * 导出生产工艺列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:process:export')")
    @Log(title = "生产工艺", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProductionProcess productionProcess)
    {
        List<ProductionProcess> list = productionProcessService.selectProductionProcessList(productionProcess);
        ExcelUtil<ProductionProcess> util = new ExcelUtil<ProductionProcess>(ProductionProcess.class);
        return util.exportExcel(list, "生产工艺数据");
    }

    /**
     * 获取生产工艺详细信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:process:query')")
    @GetMapping(value = "/{psId}")
    public AjaxResult getInfo(@PathVariable("psId") Long psId)
    {
        return AjaxResult.success(productionProcessService.selectProductionProcessById(psId));
    }

    /**
     * 新增生产工艺
     */
    @PreAuthorize("@ss.hasPermi('enterprise:process:add')")
    @Log(title = "生产工艺", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductionProcess productionProcess)
    {
        return toAjax(productionProcessService.insertProductionProcess(productionProcess));
    }

    /**
     * 修改生产工艺
     */
    @PreAuthorize("@ss.hasPermi('enterprise:process:edit')")
    @Log(title = "生产工艺", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductionProcess productionProcess)
    {
        return toAjax(productionProcessService.updateProductionProcess(productionProcess));
    }

    /**
     * 删除生产工艺
     */
    @PreAuthorize("@ss.hasPermi('enterprise:process:remove')")
    @Log(title = "生产工艺", businessType = BusinessType.DELETE)
	@DeleteMapping("/{psIds}")
    public AjaxResult remove(@PathVariable Long[] psIds)
    {
        return toAjax(productionProcessService.deleteProductionProcessByIds(psIds));
    }
}
